//
//  FouceHostViewController.m
//  penzer
//
//  Created by caiyc on 2018/10/1.
//  Copyright © 2018年 caiyc. All rights reserved.
//

#import "FouceHostViewController.h"
#import "Focus_Cell.h"
#import "HostDetailViewController.h"
@interface FouceHostViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)NSMutableArray *dataSouce;
@property(assign)NSInteger pageIndex;
@end

@implementation FouceHostViewController
-(NSMutableArray *)dataSouce{
    if(!_dataSouce){
        _dataSouce = [NSMutableArray array];
    }
    return _dataSouce;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavigation:1 andTitle:@"关注的主播" andNaviColor:nil andTitleColor:nil];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
    self.pageIndex=1;
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self
                                                                    refreshingAction:@selector(loadData)];
    [self loadData];
    // Do any additional setup after loading the view from its nib.
}
-(void)loadData{
    NSDictionary *param = @{@"ctrl":@"live",@"ac":@"member",@"op":@"member",@"ta":@"myatten",@"psize":@"10",@"page":[NSString stringWithFormat:@"%ld",(long)self.pageIndex]};
    [self weqPostHandle:param success:^(id response) {
        [self.tableView.mj_footer endRefreshing];
        if(response){
            if(self.pageIndex==1){
                [self.dataSouce removeAllObjects];
            }
            [self.dataSouce addObjectsFromArray:response[@"data"]];
            [self.tableView reloadData];
            self.pageIndex++;
        }else{
            [self.dataSouce addObjectsFromArray:response[@"data"]];
            [self.tableView reloadData];
        }
    } failure:^(NSError *error) {
         [self.tableView.mj_footer endRefreshing];
    }];
}
-(void)calcel{
   
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSouce.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellId = @"cell";
    Focus_Cell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if(!cell){
        cell = [[[NSBundle mainBundle]loadNibNamed:@"Focus_Cell" owner:self options:nil]lastObject];
    }
    cell.cancels=^(){
         NSDictionary *param = @{@"ctrl":@"live",@"ac":@"member",@"op":@"member",@"ta":@"del_atten",@"fans_id":[NSString stringWithFormat:@"%@",self.dataSouce[indexPath.row][@"fans_id"]]};
        [self weqPostHandle:param success:^(id response) {
            if(response){
                [WToast showWithText:@"取消成功"];
            self.pageIndex=1;
            [self loadData];
            }
        } failure:^(NSError *error) {
            
        }];
    };
    [cell bindData:self.dataSouce[indexPath.row]];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    HostDetailViewController *vc = [[HostDetailViewController alloc]init];
    vc.hostid = self.dataSouce[indexPath.row][@"anchor_id"];
    [self pushSecondVC:vc];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
